﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LanSunStudio.Core.Events;
using LanSunStudio.ExClassLib;
using LanSunStudio.ExClassLib.MessageExtention; 
using System.Data;
using System.Collections;
namespace LanSunStudio.Service.RTIService
{
    public class FedreateMessage
    {
        public string FedreateCallbackPath;
        public string MinMessageTimeStamp;
        public string MaxMessageTimeStamp;
        public FedreateMessage()
        {
        }
        public FedreateMessage(string m_FedreateCallbackPath, string m_MinMessageTimeStamp, string m_MaxMessageTimeStamp)
        {
            FedreateCallbackPath = m_FedreateCallbackPath;
            MinMessageTimeStamp = m_MinMessageTimeStamp;
            MaxMessageTimeStamp = m_MaxMessageTimeStamp;
        }
    }
    public class WRTIService
    {
        #region ----------------SINGLETON----------------
        public static readonly WRTIService Instance = new WRTIService();
        private string RTITime;
        public Fedration MasterFedration;
        /// <summary>
        /// Private constructor for singleton pattern
        /// </summary>
        private WRTIService()
        {
            RTITime = DateTime.Now.ToUniversalTime().ToString();
            MasterFedration = new Fedration(); 
        }
        #endregion 
        #region ----------------TIME SERVICE--------------
        public string GetRTITime()
        {
            return DateTime.Now.ToUniversalTime().ToString();
        }
        #endregion
        #region--------------------FEDRERATION MANAGEMENT-------
        public void JoinFedration(string Fedratetype, MessageEx msg)
        {
            try
            {
                Fedrate newFedrate = new Fedrate(Fedratetype, msg.AgentCallbackPath, MasterFedration);
                MasterFedration.Add(newFedrate);
                FedreateMessage newmsg = new FedreateMessage(newFedrate.CallbackPath, msg.TimeStamp, msg.TimeStamp);
                MessageMatrix.Add(newmsg);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        #endregion
         #region ----------------PROPERTIES---------------- 
        public ArrayList MessageMatrix; 
        #endregion
    }
} 